import { request } from '@/utils/request/request';
import type { BaseResponse } from '@/utils/request/request';
import { RequestEnum } from '@/enums/httpEnum';

export const userApi = {
  userList: '/user/list',
  userDetail: '/user/info',
  userAdd: '/user/add',
  userUpdate: '/user/updatePersonalData',
  sendRegisterCaptchaByEmail: '/sendRegisterCaptchaByEmail',
  register: '/register',
  login: '/login',
  logout: '/logout',
} as const;

// export const updateUser = (data: API.UpdateUserParams) => {
//   return request({
//     url: userApi.userUpdate,
//     method: RequestEnum.PUT,
//     data,
//   });
// };

export const userInfo = () => {
  return request({
    url: userApi.userDetail,
    method: RequestEnum.GET,
  });
};

export const sendRegisterCaptchaByEmail = (data: { email: string }) => {
  return request({
    url: userApi.sendRegisterCaptchaByEmail,
    method: RequestEnum.POST,
    data,
  });
};

export const captchaRegister = (data: { account: string; captcha: string; password: string }) => {
  return request<BaseResponse<API.LoginResult>>({
    url: userApi.register,
    method: RequestEnum.POST,
    data,
  });
};

export const updatePersonal = (data: API.updateUser) => {
  return request({
    url: userApi.userUpdate,
    method: RequestEnum.POST,
    data,
  });
};

export const login = (data: API.LoginParams) => {
  return request<BaseResponse<API.LoginResult>>({
    url: userApi.login,
    method: RequestEnum.POST,
    data,
  });
};

export const logout = () => {
  return request({
    url: userApi.logout,
    method: RequestEnum.POST,
  });
};
